package com.itheima.tanhua.web;

import com.itheima.tanhua.service.RecommendService;
import com.itheima.tanhua.service.TanhuaService;
import com.itheima.tanhuan.vo.mongo.NearUserVo;
import com.itheima.tanhuan.vo.mongo.PageResult;
import com.itheima.tanhuan.vo.mongo.TodayBestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("tanhua")
public class TanhuaController {

    @Autowired
    private RecommendService recommendService;
    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 1、今日佳人
     * @return
     */
    @GetMapping("todayBest")
    public ResponseEntity todayBest(){
        TodayBestVo todayBestVo=recommendService.todayBest();
        return ResponseEntity.ok(todayBestVo);
    }

    /**
     * 2、佳人推荐列表
     * @return
     */
    @GetMapping("recommendation")
    public ResponseEntity recommendation(@RequestHeader("Authorization") String token,
                                         @RequestParam(value = "page",defaultValue = "1") Integer page,
                                         @RequestParam(value = "pagesize",defaultValue = "10")Integer pagesize){
        PageResult result=recommendService.recommendation(token,page,pagesize);
        return ResponseEntity.ok(result);
    }


    /**
     * 查看佳人详情
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBestVo best = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(best);
    }

    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String questions = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }


    /**
     * 回复陌生人问题
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map) {
        //前端传递的userId:是Integer类型的
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-推荐用户列表
     */
    @GetMapping("/cards")
    public ResponseEntity queryCardsList() {
        List<TodayBestVo> list = this.tanhuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }


    /**todo 优化
     * 喜欢
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long likeUserId) {
        this.tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }
    /**todo 优化
     * 不喜欢
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable("id") Long likeUserId) {
        this.tanhuaService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender,
                                                          @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> list = this.tanhuaService.queryNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }

}
